<?php

/**
 * Created by PhpStorm.
 * User: cwy
 * Date: 14-8-27
 * Time: 下午4:01
 */
class Skusystemapi
{
    public $server_url = null;
    /**
     * 获得可销售的SKU(即原始状态为1,2,6,7,8)
     */
    public static function getSale()
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSale');
        $results    = $client->getinfo();
        return $results;

//        $flag=0;
//        $sql = "SELECT sku FROM skusystem_status_skuss WHERE status_id = 1";
//        if($flag==0){
//            $sql .= " AND isavailable=1";
//        }
//        $sql .= " ORDER BY sku";
//        $results = DB::query(Database::SELECT,$sql)
//            ->execute('newerp')
//            ->as_array();
//        return $results;

    }
    /**
     * 获得可销售和缺货的SKU(即原始状态为1,2,3,6,7,8)
     */
    public static function getSaleSku()
    {
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSaleSku');
        $results    = $client->getinfo();
        return $results;*/

        $flag=0;
        $sql = "SELECT sku FROM skusystem_status_skuss WHERE (status_id = 1 OR status_id = 3)";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $sql .= " ORDER BY sku";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     *获得可销售的指定的sku
     */
    public static function getSaleAndSku($sku)
    {
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSaleAndSku');
        $results    = $client->getinfo($sku);
        return $results;*/

        $flag=0;
        $sku = strtoupper(mysql_escape_string(trim($sku)));
        $sql = "SELECT sku FROM skusystem_status_skuss WHERE (status_id = 1 OR status_id = 3)
                        AND sku = '$sku'";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     * 根据sku查询sku状态(可销售,缺货,工厂包材)
     */
    public static function getSkuStatus($sku)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuStatus');
        $results    = $client->getinfo($sku);
        return $results;
       /* $flag=0;
        $sku = strtoupper(mysql_escape_string(trim($sku)));
        $sql = "SELECT status FROM skusystem_status_skuss AS a JOIN skusystem_statuss AS b ON a.status_id=b.id AND sku='$sku'";
        if($flag==0){
            $sql .= " AND a.isavailable=1";
        }
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;*/

    }
    /**
     * 根据多个sku返回sku的状态ID,状态和sku
     */
    public static function getSkuAndStatus($sku_arr)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuAndStatus');
        $results    = $client->getinfo($sku_arr);
        return $results;

        $flag=0;
        $results = DB::SELECT('sku','status_id','status')
            ->from('skusystem_status_skuss')
            ->join('skusystem_statuss')
            ->on('skusystem_status_skuss.status_id','=','skusystem_statuss.id');
        if($flag==0){
            $results = $results->where('skusystem_status_skuss.isavailable','=',1);
        }
        $results = $results->where('skusystem_status_skuss.sku','in',$sku_arr)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
//      -----------------------------------User------------------------------------------
    /**
     * 查询所有的用户ID和姓名
     */
    public static function getAllUser(){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putAllUser');
        $results    = $client->getinfo();
        return $results;*/

        $sql     = "SELECT id,nick FROM skusystem_users";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     * 根据用户真实姓名查询用户ID
     */
    public static function getUser($name){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putUser');
        $results    = $client->getinfo($name);
        return $results;*/

        $name    = mysql_escape_string(trim($name));
        $sql     = "SELECT id FROM skusystem_users WHERE name='$name'";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->current();
        return $results;

    }
    /*
     * 根据sku获取用户id
     */
    public static function getUserSku($sku){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putUserSku');
        $results    = $client->getinfo($sku);
        return $results;*/

        $flag=0;
        $sku = mysql_escape_string(trim($sku));
        $sql = "SELECT user_id FROM skusystem_user_skus WHERE sku='".$sku."'";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $sql .= "  ORDER BY id DESC";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     * 根据user_id获取该用户的所有sku
     */
    public static function getUserAllSku($user_id){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putUserAllSku');
        $results    = $client->getinfo($user_id);
        return $results;*/

        $flag=0;
        $sku = intval($user_id);
        $sql = "SELECT sku FROM skusystem_user_skus WHERE user_id=$user_id";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     * 根据用户昵称获取该用户的所有sku
     */
    public static function getUserAllSkuByNick($nick){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client('http://192.168.5.5:802/newerpapi/putUserAllSkuByNick');
        $results    = $client->getinfo($nick);
        return $results;*/

        $re      = array();
        $user_id = DB::select('id')
            ->from('skusystem_users')
            ->where('nick','=',trim($nick))
            ->execute('newerp')
            ->get('id',0);

        $sql = 'SELECT sku FROM skusystem_user_skus WHERE user_id ='.$user_id.' AND isavailable = 1';

        return DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();

    }
    /**
     * 根据用户id获取用户昵称
     */
    public static function getUserNick($id){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putUserNick');
        $results    = $client->getinfo($id);
        return $results;*/

        $id      = intval($id);
        $sql     = "SELECT nick FROM skusystem_users WHERE id='$id'";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->current();
        return $results;

    }
    //      ----------------------------------SKU-------------------------------------------
    /**
     * 根据模糊查询获得前15条sku
     */
    public static function getLikeSku($sku,$limit = 15){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putLikeSku');
        $results    = $client->getinfo($sku,$limit);
        return $results;*/

        $flag=0;
        $sku = mysql_escape_string(trim($sku));
        $sql = "SELECT sku FROM skusystem_skus WHERE sku like '%$sku%'";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $sql .= " LIMIT 0,".$limit;
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     * 获得sku
     */
    public static function getSku($sku){
        $sku = addslashes(trim($sku));
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSku');
        $results    = $client->getinfo($sku);
        return $results;

        /*$flag=0;
        $sku = mysql_escape_string(trim($sku));
        $sql = "SELECT id FROM skusystem_skus WHERE sku='$sku'";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->current();
        return $results;*/

    }
    /**
     * 查询所有的SKU
     */
    public static function getAllSku(){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putAllSku');
        $results    = $client->getinfo();
        return $results;*/
        $flag = 0;
        $sql = "SELECT sku FROM skusystem_skus WHERE 1";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    /**
     * 查询指定的SKU
     */
    public static function getSkuIn($sku_str){
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuIn');
        $results    = $client->getinfo($sku_str);
        return $results;*/
        $flag=0;
        $sku = mysql_escape_string(trim($sku_str));
        $sql = "SELECT TRIM(UPPER (sku)) 'sku' FROM skusystem_skus WHERE 1";
        if($flag==0){
            $sql .= " AND isavailable=1";
        }
        $sql .= " AND sku in (".$sku_str.")";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;

    }
    
    /**
     * 获得sku的一个中文名称
     */
    public static function getSkuCnname($sku)
    {
       require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
       $server_url = Kohana::$config->load('server_url');
       if(is_array($sku)){
            $skus = "('" . implode("','", array_map('addslashes', $sku)) . "')";
            $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/getmoreSkuCnname');
            $results    = $client->getinfo($skus);
            if($results instanceof PHPRPC_Error) {
                return false;
            } else {
                $data = array();
                $arr = json_decode($results, true);
                if(is_array($arr)) {
                    foreach($arr as $row) {
                        $data[$row['sku']] = $row;
                    }
                }
                return $data;
            }
       }else{
           $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuCnname');
           $results    = $client->getinfo($sku);
           return $results;
       }


//        $sku     = mysql_escape_string(trim($sku));
//        $sql     = "SELECT name FROM skusystem_sku_cnname AS a,skusystem_cnname AS b WHERE a.attr_id=b.id AND sku = '$sku'";
//        $results = DB::query(Database::SELECT,$sql)
//            ->execute('newerp')
//            ->as_array();
//        return $results;

    }

    /**
     * 获得sku的成本价
     */
    public static function getSkuPrice($sku)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $sku        = mysql_escape_string(trim($sku));
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuPrice');
        $results    = $client->getinfo($sku);
        return $results;

//        $sku     = mysql_escape_string(trim($sku));
//        $sql     = "SELECT num FROM skusystem_price WHERE sku='$sku'";
//        $results = DB::query(Database::SELECT,$sql)
//            ->execute('newerp')
//            ->as_array();
//        return $results;

    }

    /**
     * 批量获得sku的成本价
     */
    public static function getSkuArrPrice($skuArr = array())
    {
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuArrPrice');
        $results    = $client->getinfo($skuArr);
        return $results;*/

        $skuArrStr = "'".join("','",$skuArr)."'";
        $sql       = "SELECT sku,num FROM skusystem_price WHERE sku IN ({$skuArrStr})";
        $results   = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array('sku','num');
        return $results;

    }

    /**
     * 批量获得sku的物流属性
     */
    public static function getSkuArrAttr($skuArr = array())
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuArrAttr');
        $results    = $client->getinfo($skuArr);
        return $results;

        /*$skuArrStr = "'".join("','",$skuArr)."'";
        $sql       = "SELECT sku,logic_attr FROM skusystem_sku_logic WHERE sku IN ({$skuArrStr})";
        $results   = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array('sku','logic_attr');
        return $results;*/

    }

    /**
     * 批量更新sku的物流属性
     */
    public static function updateSkuArrAttr($attrs = array())
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/updateSkuArrAttr');
        $results    = $client->getinfo($attrs);
        return $results;
    }

    /**
     * 获得sku包装后的成本价
     */
    public static function getSkuAsprice($sku)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $sku     = mysql_escape_string(trim($sku));
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuAsprice');
        $results    = $client->getinfo($sku);
        return $results;

        /*$sku     = mysql_escape_string(trim($sku));
        $sql     = "SELECT num FROM skusystem_asprice WHERE sku='$sku'";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return $results;*/

    }
    /**
     * 获得sku的一个储位
     */
    public static function getSkuPlace($sku)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuPlace');
        $results    = $client->getinfo($sku);
        return $results;
//        $ware_id = Kohana::$config->load('warehouse')->warehouse_id;
//        $flag=0;
//        $sku = mysql_escape_string(trim($sku));
//        $sql = "SELECT b.place FROM skusystem_place_skus AS a,skusystem_places AS b WHERE a.place_id=b.id
//                        AND a.sku='$sku' and b.warehouse_id = $ware_id";
//        if($flag==0){
//            $sql .= " AND a.isavailable=1";
//        }
//        $results = DB::query(Database::SELECT,$sql)
//            ->execute('newerp')
//            ->as_array();
//        return $results;
    }
    /*
    * 根据sku获取图片路径
    */
    public static function getSkuImage($sku)
    {
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putSkuImage');
        $results    = $client->getinfo($sku);
        return $results;*/
        $server_url = Kohana::$config->load('server_url');
        $sku   = mysql_escape_string(trim($sku));
        $sql   = "SELECT file_name FROM skusystem_image
            WHERE sku = '$sku' AND file_name LIKE '%-TALL-%'";
        $image = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->current();
        if($image){
            $arr               = explode(".",$image['file_name']);
            $image['filename'] = $server_url['server'].'/getimage/conversion_image/'.$arr[0];
        }
        return $image;
    }
    /**
     * 描述:获取sku图片库图片
     * 参数: array(
            "sku"        => 'A301',
            "gallery_id" => '1',
            "type"       => "ALL",
            "all_type"   => "false",
            "url_type"   => 'http'
            )
     * 作者:kelvin
     */
    public static function getSkuSystemImgData($postData) {
        $server_url = Kohana::$config->load('server_url');
        $url =$server_url['server_img']. '/api/?c=api_pictureurl_urlservers&a=get_pictureurl';
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        $output = curl_exec($ch);
        curl_close($ch);
        $data = json_decode($output,true);
        $re = current(current(current(current($data))));
        if($re){
            return $re;
        }else{
            return null;
        }
    }

    /**
     * 可销售 $status='sale'
     * 不可销售 $status= 'unsale'
     * 缺货 $status= 'missing'
     * 知识产权下架 $status = 'invasion'
     * 清货下架 $status= 'clear'
     * 工厂包材 $status= 'packaging'
     * 其他原因下架 $status = 'others'
     * @param     $status
     * @param int $flag
     * @return mixed
     */
    public static function getOneStatusSkus($status,$flag = 0)
    {
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/putOneStatus');
        $results    = $client->getinfo($status,$flag = 0);
        return $results;*/

        $statusapi = Kohana::$config->load('statusapi');
        if(isset($statusapi[$status])){
            $num = $statusapi[$status];
            $sql = "SELECT sku FROM skusystem_status_skuss WHERE status_id=$num";
            if($flag==0){
                $sql .= " AND isavailable=1";
            }
            $results = DB::query(Database::SELECT,$sql)
                ->execute('newerp')
                ->as_array();
        }else{
            $results = array();
        }
        return $results;

    }

    /**
     * 通过SKU数组查询SKU的中文名称
     * @param     $sku_arr
     * @param int $flag
     * @return mixed
     */
    public static function getMoreSkuCnname($sku_arr)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/getmoreSkuCnname');
        $sku_arr    = trim($sku_arr);
        $results    = $client->getinfo($sku_arr);
        return $results;

        /*$sku     = trim($sku_arr);
        $sql     = "SELECT name,sku FROM skusystem_sku_cnname AS a,skusystem_cnname AS b WHERE a.attr_id=b.id AND sku IN ".$sku_arr;
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        return json_encode($results);*/

    }

    public static function getSkuPlacesForVMI($sku, $warehouse_id) {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client($server_url['server'].'/newerpapi/getSkuPlaceForVMI');
        $results    = $client->getinfo($sku, $warehouse_id);
        return $results;
    }

    /**
     * 批量获取SKU的储位信息
     * @author zhjx
     * @param $sku_arr
     * @return mixed
     */
    public static function getSkuPlaces($skus)
    {
        /*require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $client     = new PHPRPC_Client('192.168.5.5:802/newerpapi/getSkuPlaces');
        $results    = $client->getinfo($sku_arr);
        return $results;*/

        $flag = 0;
        //查询出全部ｓｋｕ_place
        $sql        = "SELECT sku FROM skusystem_place_skus";
        $skus_sql   = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        $array_skus = array();
        foreach($skus_sql as $sku_sql){
            $array_skus[] = $sku_sql['sku'];
        }
        //查询出差集
        $skus_diff = array_diff($skus,$array_skus);
        //查询出交集
        $skus_inter = array_intersect($skus,$array_skus);

        $flag    = 0;
        $sku_arr = "(";
        foreach($skus_inter as $sku){
            $sku_arr .= "'".mysql_escape_string(trim($sku))."',";
        }
        $sku_arr .= ")";
        $sku_arr = str_replace(",)",")",$sku_arr);
        $sql     = "SELECT sku, place
                        FROM (
                        SELECT a.sku, b.place
                        FROM skusystem_place_skus AS a, skusystem_places AS b
                        WHERE a.place_id = b.id";
        if($flag==0){
            $sql .= " AND a.isavailable=1";
        }
        $sql .= " AND a.sku
                        IN $sku_arr
                        ORDER BY a.id DESC
                        ) AS n
                        GROUP BY sku
                        ";
        $results = DB::query(Database::SELECT,$sql)
            ->execute('newerp')
            ->as_array();
        foreach($skus_diff as $diff){
            $array_diff = array(
                'sku'   => $diff,
                'place' => ''
            );
            array_push($results,$array_diff);
        }
        return $results;

    }
    /**
     * 描述:根据sku获取跟单员
     * 作者:kelvin
     */
    public static function getSkuMerchandiser($sku)
    {
        require_once(Kohana::find_file('vendor','phprpc/phprpc_client'));
        $server_url = Kohana::$config->load('server_url');
        $url = $server_url['server']."/newerpapi/putUserbySku";
        $client = new \PHPRPC_Client($url);
        $skuinfo = $client->getinfo($sku,2);
        return $skuinfo?$skuinfo[$sku]['nick']:'';
    }
    /**
     * 描述:通过sku获取sku基础资料库信息(对接sku基础资料库)
     * 参数:string $sku
     * 返回:return array
     * 作者:kelvin
     */
    public static function getSkuInfoByBase($sku){
        if(empty($sku)){
            return false;
        }
        //请求基础资料库的接口
        $data=array('sku'=>$sku);
        $handle = curl_init();
        $server_url = Kohana::$config->load('server_url');
//        $url = 'http://dev.skusystem.kokoerp.com/putskuinfotopublishapi/skuinfo';
        $url = $server_url['server'].'/putskuinfotopublishapi/skuinfo';//正式
        curl_setopt($handle,CURLOPT_URL,$url);
        curl_setopt($handle,CURLOPT_RETURNTRANSFER,TRUE);
//        curl_setopt($handle,CURLOPT_USERAGENT,'Fbawarehouse API/1.0');
        curl_setopt($handle,CURLOPT_CONNECTTIMEOUT,60);
        curl_setopt($handle,CURLOPT_TIMEOUT,90);
        curl_setopt($handle,CURLOPT_MAXREDIRS,3);
        curl_setopt($handle,CURLOPT_POST,TRUE);
        curl_setopt($handle,CURLOPT_POSTFIELDS,http_build_query($data));
        curl_setopt($handle,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
        curl_setopt($handle,CURLOPT_HEADER,FALSE);    //不返回头信息
        $response = curl_exec($handle);
        $result=json_decode($response,true);
        if($result['status']==200 && !empty($result['data'])){
            return $result['data'];
        }else{
            return false;
        }
    }
}